﻿using DevExpress.Data;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DXApplicationTangche.UC.面料审核.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.面料审核.生产计划UC
{
    public partial class XtraUserControl每日进出库明细 : DevExpress.XtraEditors.XtraUserControl
    {
        private List<GarmentStockDTO> garmentStockDTOs = new List<GarmentStockDTO>();
        public XtraUserControl每日进出库明细()
        {
            InitializeComponent();
        }
        public XtraUserControl每日进出库明细(List<GarmentStockDTO> garmentStockDTOs)
        {
            InitializeComponent();
            this.garmentStockDTOs = garmentStockDTOs;
            foreach(GarmentStockDTO garmentStockDTO in this.garmentStockDTOs)
            {
                try { garmentStockDTO.styleSizeCd = garmentStockDTO.styleSizeCd.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
            }
            this.gridControl库存.DataSource = this.garmentStockDTOs;
            this.gridView1.ExpandAllGroups();
            this.gridView1.RefreshData();
            this.gridView1.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Count, "barcode", null, "(数量总计= {0})"), });
            //this.gridView1.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Sum, "price", null, "(金额总计= {0})"), });
        }

        private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.Name.Equals("gridColumn尺寸"))
            {
                if (!String.IsNullOrWhiteSpace(e.DisplayText))
                {
                    try { e.DisplayText = e.DisplayText.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                }
                else
                {
                    e.DisplayText = "样衣无尺寸定义";
                }
            }
        }

        private void 导出出入库明细ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.garmentStockDTOs.Count() == 0)
            {
                MessageBox.Show("请先选择导出数据");
                return;
            }

            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出出入库明细";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridControl库存.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
